import { observable, action } from 'mobx';
import { WeaTableNew } from 'comsMobx';

const { TableStore } = WeaTableNew;
import { WeaTools } from 'ecCom';

import ListBaseStore from './ListBaseStore';
import Apis from '../apis/car';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
/**
 * 车辆查询Store
 */
export default class CarUseContainerStore extends ListBaseStore {
	@observable org = {};

	constructor() {
	  super();
	  this.isFormInitOver = false;
	  this.title = getLabel(19018, '车辆使用情况');
	  this.selectedKey = 'all';
	}

	// 加载列表数据
	@action doTableLoading = (params) => {
	  this.showLoading(true);
	  let resultParams = this.getFormParams();
	  const commonParams = {
	    searchType: this.selectedKey ? this.selectedKey : 'all',
	  };
	  resultParams = { ...resultParams, ...commonParams, ...params };
	  Apis.getCarReportList(resultParams).then(
	    (result) => {
	      const sessionkey = result.sessionkey;
	      this.sessionkey = sessionkey;
	      this.tableStore.getDatas(sessionkey, 1);

	      this.showLoading(false);
	    },
	  );
	}

	// 初始化车辆查询页面查询条件
	@action initConditionDatas = (params) => {
	  Apis.getCarViewSearchListCondition(params).then(
	    (result) => {
	      const { conditioninfo } = result;
	      this.conditioninfo = conditioninfo;
	      this.initFormFields(conditioninfo); // 一定要先初始化initFormFields表单对象
	    },
	  );
	}

	// 获取创建车辆流程的数据
	@action getCarFlowCreateData = (callback, params) => {
	  Apis.getCarFlowCreateData().then(
	    (result) => {
	      if (callback) {
	        callback(result, params);
	      }
	    },
	  );
	}

	// 撤销
	@action doCancel = (params, callback) => {
	  Apis.doCancel(params).then(
	    (result) => {
	      if (callback) {
	        callback();
	      }
	    },
	  );
	}
}
